package com.project.servlet;

import com.project.Util.UtfUtil;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;

/**
 * @author lyl
 * description:servlet测试类
 */
public class TestServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }


    /**
     * @param req  请求（接口，由容器进行实现）
     * @param resp 响应（接口，由容器进行实现）
     * @throws ServletException
     * @throws IOException
     */
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        UtfUtil.utfUtil(req, resp);
        String info = "";
        info += "用户名：" + req.getParameter("username") + "<br>";
        info += "性别" + req.getParameter("sex") + "<br>";
        info += "学历" + req.getParameter("edu") + "<br>";
        //获取请求下多个同名的键值对值，一般用于复选框筛选
        String[] values = req.getParameterValues("like");
        info += "爱好" + Arrays.toString(values) + "<br>";
        //得到打印流，可以向客户端输出文本数据
        PrintWriter pw = resp.getWriter();
        pw.println(info);
    }
}
